package junit;

import base.AST;
import base.Identifier;
import base.Interpreter;
import expressions.*;
import instructions.*;
import values.FantaString;
import values.Integer;

public class TestWhile {

	public static void main(String args[]) {

		int start = 0;
		int end = 10;

		/*
		 * x = 0; y = 10;
		 * 
		 * i = x;
		 * 
		 * while (i <= y) { print(i); i = i + 1; }
		 */

		// /////////////////////////////////////////

		// SubFibo :

		Identifier x = new Identifier("x");
		Identifier y = new Identifier("y");
		Identifier i = new Identifier("i");

		VariableAssign xVal = new VariableAssign(x, new Integer(start));
		VariableAssign yVal = new VariableAssign(y, new Integer(end));
		VariableAssign iVal = new VariableAssign(i, new VariableAccess(x));

		Print print = new Print(new VariableAccess(i));
		VariableAssign iInc = new VariableAssign(i, new Add(new VariableAccess(
				i), new Integer(1)));
		Composition whileBody = new Composition(print, iInc);

		LessEqual test = new LessEqual(new VariableAccess(i),
				new VariableAccess(y));
		While whileLoop = new While(test, whileBody);

		Composition compo1 = new Composition(xVal, yVal);
		Composition compo2 = new Composition(compo1, iVal);
		Composition finalcompo = new Composition(compo2, whileLoop);

		System.out.println("Sould print integers from " + start + " to " + end);
		
		Interpreter.instr(finalcompo);
	}
}
